<template>
  <div class="view-publication-wrapper page-wrapper">
    <div class="page-title">
      <!-- Students 学生 -->
    </div>
    <div class="publication-container">
      <a name="paper" />
      <div class="container">
        <h3>{{$store.state.language === 'zh-CN' ? '论文著作' : 'Papers'}}</h3>
        <div class="publication-list">
          <div class="publication-instance" v-for="(item,_) in pubList" :key="item.id">
            <div class="icon">
              <i class="el-icon-star-off"></i>
            </div>
            <div class="content" v-html="item.content">{{item.content}}</div>
            <div class="head">
              <img :src="headImgUrl" />
              <span class="text">{{_ + 1}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="copyright-container">
      <a name="copyright" />
      <div class="container" v-if="$store.state.language === 'zh-CN'">
        <h3>专利</h3>
        <div class="copyright-list">
          <div class="copyright-instance" v-for="(item,_) in copyRightList" :key="item.id">
            <div class="icon">
              <i class="el-icon-paperclip"></i>
            </div>
            <div class="content" v-html="item.content">{{item.content}}</div>
            <div class="head">
              <img :src="headImgUrl" />
              <span class="text">{{_ + 1}}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="container" v-else>
        <h3>Patents</h3>
        <div class="copyright-list">
          <div class="copyright-instance" v-for="(item,_) in enCopyRightList" :key="item.id">
            <div class="icon">
              <i class="el-icon-paperclip"></i>
            </div>
            <div class="content" v-html="item.content">{{item.content}}</div>
            <div class="head">
              <img :src="headImgUrl" />
              <span class="text">{{_ + 1}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="book-container">
      <a name="book" />
      <div class="container" v-if="$store.state.language === 'zh-CN'">
        <h3>出版书籍</h3>
        <div class="book-list">
          <div class="book-instance" v-for="(item,_) in bookList" :key="item.id">
            <div class="icon">
              <i class="el-icon-reading"></i>
            </div>
            <div class="content" v-html="item.content">{{item.content}}</div>
            <div class="head">
              <img :src="headImgUrl" />
              <span class="text">{{_ + 1}}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="container" v-else>
        <h3>Book Chapters</h3>
        <div class="book-list">
          <div class="book-instance" v-for="(item,_) in enBookList" :key="item.id">
            <div class="icon">
              <i class="el-icon-reading"></i>
            </div>
            <div class="content" v-html="item.content">{{item.content}}</div>
            <div class="head">
              <img :src="headImgUrl" />
              <span class="text">{{_ + 1}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { RequestStatus } from "../utils/constans";
import { formatBackTime } from "../utils/common";
import { iPublication, iBook } from "../typings/publication";
import { iCopyRight } from "../typings/research";

import $api from "../api";

@Component
export default class StudnetsView extends Vue {
  private pubList: iPublication[] = [];

  private copyRightList: iCopyRight[] = [];
  private enCopyRightList: iCopyRight[] = [];

  private bookList: iBook[] = [];
  private enBookList: iBook[] = [];

  private headImgUrl: string = require("../assets/pub-head.png");

  mounted() {
    this.getPublicationList();
    this.getCopyRightList();
    this.getBooksList();
  }

  getPublicationList() {
    $api.publication.findAllPublicationClient().then(res => {
      (res as any).map((record: iPublication) => {
        record.content = record.content.replace(
          "Tie Qiu",
          "<strong>Tie Qiu</strong>"
        );
        this.pubList.push(record);
      });
    });
  }

  getCopyRightList() {
    $api.research.findAllPatentsCopyrightClient().then(res => {
      (res as any).map((record: iCopyRight) => {
        record.content = record.content.replace(
          "Tie Qiu",
          "<strong>Tie Qiu</strong>"
        );
        record.content = record.content.replace(
          "邱铁",
          "<strong>邱铁</strong>"
        );

        if (record.language === "英语") {
          this.enCopyRightList.push(record);
        } else if (record.language !== "英语") {
          this.copyRightList.push(record);
        }
      });
    });
  }

  getBooksList() {
    $api.publication.findAllBookClient().then(res => {
      (res as any).map((record: iBook) => {
        record.content = record.content.replace(
          "Tie Qiu",
          "<strong>Tie Qiu</strong>"
        );
        record.content = record.content.replace(
          "邱铁",
          "<strong>邱铁</strong>"
        );
        if (record.language === "英语") {
          this.enBookList.push(record);
        } else if (record.language !== "英语") {
          this.bookList.push(record);
        }
      });
    });
  }
}
</script>

<style lang="scss" scoped>
.view-publication-wrapper {
  text-align: left;
  .container {
    width: 1200px;
    margin: auto;
  }
  .publication-container,
  .book-container {
    background: #f7f8fa;
    padding: 30px 0;
  }
  .copyright-container {
    padding: 30px 0;
  }
  .publication-instance,
  .copyright-instance,
  .book-instance {
    position: relative;
    background: white;
    display: flex;
    padding: 20px 25px;
    margin-bottom: 10px;
    box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.05);
    .icon {
      color: #113f6c;
      margin-right: 10px;
    }
    .content {
      strong {
        color: #f5ae54;
      }
    }
    .head {
      img {
        position: absolute;
        top: -7px;
        right: -8px;
        display: block;
        width: 66px;
        z-index: 1;
      }
      .text {
        position: absolute;
        right: -4px;
        top: 16px;
        z-index: 2;
        transform: rotate(45deg);
        color: white;
        height: 20px;
        text-align: center;
        width: 54px;
        line-height: 0;
      }
    }
  }
}
@media screen and (max-width: 980px) {
  .view-publication-wrapper {
    .publication-container,
    .book-container,
    .copyright-container {
      .container {
        padding: 0 15px;
        box-sizing: border-box;
      }
    }
  }
}
</style>